#include "stdafx.h"

Property::Property(const std::wstring & name, int x, int y)
{
	this->x = x;
	this->y = y;
	curx = x;
	cury = y;

	image = ImageMgr::getInstance()->getImageFromName(L"img\\" + name + L".png");
	width = image->GetWidth();
	height = image->GetHeight();
}

Property::~Property()
{
}

bool Property::collide(Point pt)
{
	if (pt.X >= x - width / 2 && pt.X <= x + width / 2 && pt.Y >= y - height / 2 && pt.Y <= y + height / 2)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool Property::collide(Rect rc)
{
	int l = rc.GetLeft();
	int r = rc.GetRight();
	int t = rc.GetTop();
	int b = rc.GetBottom();

	double w = width / 2;
	double h = height / 2;

	return !(l < x - w && r < x - w || l > x + w && r > x + w || t < y - h && b < y - h || t > y + h && b > y + h);
}

void Property::update(double dtime)
{
	time += dtime;
	cury = y + 6 * sin(4 * time);
}

void Property::draw(Graphics * graphics)
{
	graphics->DrawImage(image, curx - width / 2, cury - height / 2, width, height);
}

//void Property::dosomething()
//{
//}

PropertyTimer::PropertyTimer(const std::wstring & picname, int x, int y) :Property(picname, x, y)
{
}

PropertyTimer::~PropertyTimer()
{
}

void PropertyTimer::dosomething()
{
	EnemyMgr::getInstance()->stop(5);
}

PropertyStar::PropertyStar(const std::wstring & picname, int x, int y) :Property(picname, x, y)
{
}

void PropertyStar::dosomething()
{
	Game::getInstance()->getHero()->powerby(1);
}

PropertyBomb::PropertyBomb(const std::wstring & picname, int x, int y) :Property(picname, x, y)
{
}

PropertyBomb::~PropertyBomb()
{
}

void PropertyBomb::dosomething()
{
	Game::getInstance()->getHero()->bombBy(1);
}